//
//  UserAgreementSwiftUIView.swift
//  ptbuy
//
//  Created by MyMac on 2024/11/11.
//

import SwiftUI
//用户第一次进入弹出协议框
struct UserAgreementSwiftUIView: View {
    @AppStorage(
        "hasAcceptedPrivacyPolicy"
    ) private var hasAcceptedPrivacyPolicy = false
    
    @State private var showAlert = false
    
    var body: some View {
        VStack {
            Text("Welcome to SwiftUI")
                .padding()
                      
            // 这里通过控制 showAlert 来自动触发 Alert
            Text("The alert will show automatically!")
                .padding()
                .onAppear {
                    // 当视图出现在屏幕上时，自动显示 Alert
                    showAlert = true
                }
        }
        .alert(isPresented: $showAlert) {
            // Alert 内容
            Alert(
                title: Text("Hello!"),
                message: Text(
                    "This alert shows automatically when the view appears."
                ),
                dismissButton: .default(Text("OK"))
            )
        }
          
    }
}

#Preview {
    UserAgreementSwiftUIView()
}
